//回顾创建http服务器

const http=require('http');
const fs=require('fs');
http.createServer().on('request',(req,res)=>{
  let newUrl=req.url;
  let suffix=newUrl.split('.')[1];
  if (suffix=='html'){
    fs.readFile(`../src/index.html`,"utf-8",function (err,data) {
      res.writeHead(200,{"content-type":"text/html;charset=utf-8"})
      res.write(data)
      res.end()
    })
  }else if(suffix=='css'){
    fs.readFile(`../src/css/day1.css`,"utf-8",function (err,data) {
      res.writeHead(200,{"content-type":"text/css;charset=utf-8"})
      res.write(data)
      res.end()
    })
  } else if(suffix=='js'){
     fs.readFile(`../src/javascript/day1.js`,"utf-8",function (err,data) {
       res.writeHead(200,{"content-type":"text/javascript;charset=utf-8"})
       res.write(data)
       res.end()
     })
   }
}).listen(8888,()=> console.log(`服务器启动成功,可以通过 http://localhost:8888/index.html 来访问`));
